package cn.uce.cc.rest.control;

import cn.uce.cc.api.service.biz.IWaybillBiz;
import cn.uce.common.cache.CcCodeCache;
import cn.uce.common.utils.CodeCacheUtils;
import cn.uce.core.cache.CacheManager;
import cn.uce.core.cache.base.ICache;
import cn.uce.ics.base.vo.cs.CsWoCustSerVo;
import cn.uce.web.common.base.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/cs/HomeScreenPopup")
public class HomeScreenPopupController extends BaseController {


    @Resource
    private IWaybillBiz waybillBiz;

    @RequestMapping(value="/findTraceInfo")
    @ResponseBody
    public Map<String, Object> findTraceInfo(String billCode){
        Map<String, Object> map = null;
        Map<String, Object> result = new HashMap<>(16);
        List<Map> icsSignList =new ArrayList<Map>();
        //处理异常
        try{
            map = waybillBiz.findTraceInfo(billCode);
            //判断返回是否有数据
            if(map != null){
                //获取签收信息
                icsSignList =(List<Map>)map.get("scan");
            }
        }catch (Exception e){
            logger.error("error", e);
        }
        result.put("rows", icsSignList);
        result.put("total", icsSignList == null ? 0: icsSignList.size());
        return result;
    }

    /**
     *
     *获取问题信息
     *updater chenqinglong 20180718
     * */
    @RequestMapping(value="/findProblemInfo")
    @ResponseBody
    public Map<String, Object>  findProblemInfo(CsWoCustSerVo csWoCustSerVo){
        Map<String, Object> result = waybillBiz.findProblemInfo(csWoCustSerVo);
        return result;
    }
    @RequestMapping(value = "findDispenseList")
    @ResponseBody
    public Map<String, Object>  findDispenseList(String billCode){
        Map<String, Object> result = waybillBiz.findDispenseList(billCode);
        return result;
    }
    /**
     * getLoginName。
     * 获取客户编码
     */
    @RequestMapping(value="/getCustomer",method= RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> getCustomer(){
        String customer = CodeCacheUtils.getCode(CcCodeCache.CUSTOMER_KEY);
        Map<String, Object> map = new HashMap<String,Object>(16);
        map.put("Customer",customer);
       /* List<Object> list = new ArrayList<>();
        list.add(map);
        String json = com.alibaba.fastjson.JSONArray.toJSONString(list);*/
        return map;
    }

}
